using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using CoreLib.Camera;
using CoreLib.Entities;
namespace CoreLib
{
    public class Engine:Game
    {

        public struct PickResult
        {
           // public C3DModel Model;
            public string Name;
            public Vector3 HitPosition;
            public bool Hit;
            public PickObject PickedObjectType;
            public float? Distance;
            public int TriangleID;
        }
        public struct CollideResult
        {
           public C3DModel Model;
            public string Name;
            public Vector3 HitPosition;
            public bool Hit;
            public CollideObject CollideObjectType;
            public float? Distance;
        }
        public enum PickObject
        {
            Model,
            SkinnedModel,
            Terrain,
        }
        public enum CollideObject
        {
            Model,
            SkinnedModel,
            Terrain,
        }
        public enum PickType
        {
            BoundingSphere,
            TrianglePicking,
        }
        public enum CollideType
        {
            BoundingSphere,
            Triangle,
        }

        public static GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        KeyboardState keyBoardState = new KeyboardState();
        static ContentManager contentManager;

        public static ContentManager ContentManager
        {
            get { return contentManager; }
            set { contentManager = value; }
        }



        public int WindowWidth
        {
            get { return graphics.GraphicsDevice.DisplayMode.Width / 2; }
           // set { windowWidth = value; }
        }


        public int WindowHeight
        {
            get { return graphics.GraphicsDevice.DisplayMode.Height / 2; }
           // set { windowHeight = value; }
        }

        private static Viewport viewport;

        public static Viewport Viewport
        {
            get { return viewport; }
            set { viewport = value; }
        }

    public static Game game;

        public Engine()
        {
            graphics = new GraphicsDeviceManager(this);
      
            Content.RootDirectory = "Content";
            game = this;
        }
        public static ThirdPersonCamera CurrentCamera;

        private static Cursor cursor;

        public static Cursor Cursor
        {
            get { return cursor; }
            set { cursor = value; }
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            CurrentCamera = new ThirdPersonCamera(this);
            Cursor = new Cursor(this);
            GameTime gameTime = new GameTime();
            this.IsFixedTimeStep = true;


            //debugDrawer.Enabled = true;
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
           
            base.LoadContent();
            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            float timeStep = (float)gameTime.ElapsedGameTime.Ticks / TimeSpan.TicksPerSecond;
           
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
   
    }
    }

